package com.cskaoyan.bean.vo.admin.auth;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: bwj
 * @Date: 2022/09/08/21:27
 * @Description: md5加密算法工具类
 */
public class Md5Util {
    public static String getMd5(String password) throws Exception {
        MessageDigest messageDigest = MessageDigest.getInstance("md5");
        byte[] passwordBytes = password.getBytes();
        byte[] resultBytes = messageDigest.digest(passwordBytes);
        StringBuffer stringBuffer = new StringBuffer();
        for (byte resultByte : resultBytes) {
            int temp =resultByte&0xff;
            String s = Integer.toHexString(temp);
            if (s.length()==1){
                stringBuffer.append(0);
            }
            stringBuffer.append(s);
        }
        return stringBuffer.toString();
    }
}
